package cn.duhengkui.national.valuelist.example;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;

import cn.duhengkui.national.poi.word.POIWordUtil;
import cn.duhengkui.national.poi.word.model.ListParamModel;
import cn.duhengkui.national.poi.word.model.WordImgModel;
import cn.duhengkui.national.valuelist.example.model.MyDiff;
import cn.duhengkui.national.valuelist.example.model.MyInfo;
import cn.duhengkui.national.valuelist.example.model.TomWork;
import cn.duhengkui.national.valuelist.example.model.WorkInfo;

public class WordExample {
	
	@Test
	public  void test(){

		try {
			POIWordUtil util = new POIWordUtil();
			String fileName = this.getClass().getClassLoader().getResource("").getPath();
			InputStream fileIo = new FileInputStream(fileName + "我的测试文档.docx");
			OutputStream os = new FileOutputStream(fileName + "我的测试文档生成.docx");
			
			Map<String, Object> whereClause = new HashMap<>();
			whereClause.put("month", "01");
			whereClause.put("date", "01");
			whereClause.put("name", "杜恒奎");
			Map<String,ListParamModel> tableParams = new HashMap<>();
			ListParamModel table = new ListParamModel();
			table.setClazz(WorkInfo.class);
			List<WorkInfo> workInfoList = new ArrayList<>();
			WorkInfo workInfo1 = new WorkInfo();
			workInfo1.setWork("工作1");
			workInfo1.setWorkDetail("工作1详情");
			WorkInfo workInfo2 = new WorkInfo();
			workInfo2.setWork("工作2");
			workInfo2.setWorkDetail("工作2详情");
			workInfoList.add(workInfo1);
			workInfoList.add(workInfo2);
			table.setParamList(workInfoList);
			tableParams.put("workInfo",table);
			
			ListParamModel table1 = new ListParamModel();
			table1.setClazz(MyDiff.class);
			MyDiff diff1 = new MyDiff();
			diff1.setMyDiff("难点1");
			
			MyDiff diff2 = new MyDiff();
			diff2.setMyDiff("难点2");
			
			List<MyDiff> diffList = new ArrayList<>();
			diffList.add(diff1);
			diffList.add(diff2);
			table1.setParamList(diffList);
			tableParams.put("workDiff", table1);
			
			ListParamModel table2 = new ListParamModel();
			table2.setClazz(TomWork.class);
			List<TomWork> tomList = new ArrayList<>();
			TomWork tomWork1 = new TomWork();
			tomWork1.setTomPlan("aaa");
			TomWork tomWork2 = new TomWork();
			tomWork2.setTomPlan("bbb");
			tomList.add(tomWork1);
			tomList.add(tomWork2);
			table2.setParamList(tomList);
			tableParams.put("tomWork", table2);
			
			Map<String, ListParamModel> paragraphParamMap = new HashMap<>();
			ListParamModel list1 = new ListParamModel();
			MyInfo info1 = new MyInfo();
			info1.setIndex(1);
			info1.setMyInfo("基本信息1");
			
			MyInfo info2 = new MyInfo();
			info2.setIndex(2);
			info2.setMyInfo("基本信息2");
			list1.setClazz(MyInfo.class);
			
			List<MyInfo> myInfoList = new ArrayList<>();
			myInfoList.add(info1);
			myInfoList.add(info2);
			list1.setParamList(myInfoList);
			paragraphParamMap.put("aa", list1);
			
			Map<String, List<WordImgModel>> imgs = new HashMap<>();
			List<WordImgModel> imageList = new ArrayList<>();
			/*WordImgModel model1 = new WordImgModel();
			File file1 = new File("D://2.jpg");
			InputStream io1 = new FileInputStream(file1);
			model1.setHeight(100);
			model1.setWidth(120);
			model1.setInputStream(io1);
			model1.setPicType(WordUtil.getPictureType("jpg"));
			
			WordImgModel model2 = new WordImgModel();
			File file2 = new File("D://3.jpg");
			InputStream io2 = new FileInputStream(file2);
			model2.setHeight(100);
			model2.setWidth(120);
			model2.setInputStream(io2);
			model2.setPicType(WordUtil.getPictureType("jpg"));
			
			imageList.add(model1);
			imageList.add(model2);*/
			
			imgs.put("imgs", imageList);
			util.processWord(fileIo, os, whereClause, tableParams, imgs, paragraphParamMap);
			/*io2.close();
			io1.close();*/
			
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		
	}

}
